package com.biomatch.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.DancePosition;
import com.biomatch.dto.Pagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.DancePositionService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("dance.position")
@RequestMapping("/danceposition")
@Api(value="舞蹈房位置管理")
public class DancePositionController {

    @Autowired
    private DancePositionService dancePositionService;

    @Autowired
    private Internationalize internationalize;

    @RequestMapping(value="/getAllPositionByPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取位置", response = DancePosition.class, httpMethod = "POST")
    public RestResult<DancePosition> getAllPositionByPage(@RequestBody Pagination pagination) {
        IPage<DancePosition> result=dancePositionService.getAllPositionByPage(pagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getAll", method = RequestMethod.POST)
    @ApiOperation(value = "获取全部位置", response = DancePosition.class, httpMethod = "POST")
    public RestResult<List<DancePosition>> getAll() {
        List<DancePosition> result =dancePositionService.getAll();
        return RestResponse.success(result);
    }

    @RequestMapping(value="/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "新增或更新位置", response = DancePosition.class, httpMethod = "POST")
    public RestResult<DancePosition> saveOrUpdate(@RequestBody DancePosition dancePosition) {
        DancePosition  result = dancePositionService.saveOrUpdate(dancePosition);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.name.repeat"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/deletePosition", method = RequestMethod.POST)
    @ApiOperation(value = "删除位置", response = DancePosition.class, httpMethod = "POST")
    public RestResult<DancePosition> delete(@RequestBody DancePosition dancePosition ) {
        DancePosition result = dancePositionService.delete(dancePosition);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.status.used"));
        } else {
            return RestResponse.success(result);
        }
    }
}
